package com.eoner.uikit.dialog.simple;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;
import com.eoner.baselibrary.utils.ScreenUtils;
import com.eoner.uikit.R;

/**
 * 作者：sean
 * 创建时间：2017/8/2 17:52
 * 功能说明：
 */

public class ChooseHeadImgDialog extends Dialog implements View.OnClickListener{

    TextView tv_album,tv_photo,tv_title;

    private String title,one,two;
    public ChooseHeadImgDialog(@NonNull Context context,String title,String one,String two) {
        super(context,R.style.MyDialog);
        this.title = title;
        this.one= one;
        this.two = two;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_choose_headimg);
        setCanceledOnTouchOutside(true);
        tv_album = (TextView) findViewById(R.id.tv_album);
        tv_photo = (TextView) findViewById(R.id.tv_photo);
        tv_title = (TextView) findViewById(R.id.tv_title);
        tv_title.setText(title);
        tv_album.setText(one);
        tv_photo.setText(two);
        tv_album.setOnClickListener(this);
        tv_photo.setOnClickListener(this);
        setCancelable(true);
    }


    @Override
    protected void onStart() {
        super.onStart();
        Window window = getWindow();
        WindowManager.LayoutParams windowparams = window.getAttributes();
        window.setGravity(Gravity.CENTER);
        windowparams.width = (int) (ScreenUtils.getScreenWidth()*0.8f);
        window.setBackgroundDrawableResource(android.R.color.transparent);
        window.setAttributes(windowparams);
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.tv_album) {
            if (onChooseListener != null) {
                onChooseListener.album();
            }
            dismiss();
        } else if (id == R.id.tv_photo) {
            if (onChooseListener != null) {
                onChooseListener.photo();
            }
            dismiss();
        }
    }

    private OnChooseListener onChooseListener;

    public void setOnChooseListener(OnChooseListener onChooseListener) {
        this.onChooseListener = onChooseListener;
    }

    public  interface OnChooseListener{
        public void album();
        public void photo();
    }
}
